﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;

namespace Watcher
{
    class ChatTab : TabPage
    {
        public Boolean m_ChatControl = false;
        private string m_ChatType = "";
        private string m_whisper_partner;

        public ChatTab(string ChatTabName, string ChatType, Boolean ChatControl, string whisper_partner = null)
        {
            this.Text = ChatTabName;
            this.Name = ChatTabName;
            this.m_ChatType = ChatType;
            this.m_whisper_partner = ChatTabName;

            m_ChatControl = ChatControl;

            

            if (ChatControl)
            {
                TextBox message = new TextBox();
                message.Name = "txt_message";
                message.Size = new Size(590, 20);
                message.Location = new Point(10, 170);
                message.KeyDown += new KeyEventHandler(send_KeyDown);

                TextBox chat = new TextBox();
                chat.Name = "text_chat";
                chat.Size = new Size(660, 150);
                chat.Location = new Point(10, 10);
                chat.Multiline = true;
                chat.ReadOnly = true;
                chat.BackColor = Color.White;
                chat.ScrollBars = ScrollBars.Vertical;
     


                Button send = new Button();
                send.Name = "Send";
                send.Location = new Point(610, 168);
                send.Text = "Send";
                send.Size = new Size(45, 23);
                send.Click += new EventHandler(send_Click);
              

                this.Controls.Add(chat);
                this.Controls.Add(message);
                this.Controls.Add(send);

            }
            else
            {
                RichTextBox text_looting = new RichTextBox();
                text_looting.Name = "text_looting";
                text_looting.Size = new Size(660, 180);
                text_looting.Location = new Point(10, 10);
                text_looting.Multiline = true;
                text_looting.ReadOnly = true;
                text_looting.BackColor = Color.White;
                text_looting.ForeColor = Color.Green;
                text_looting.ScrollBars = RichTextBoxScrollBars.Vertical;

                this.Controls.Add(text_looting);
            }

            this.ImageIndex = 0;
        }


        void SendMessageToWow()
        {
            TabControl p = (TabControl)this.Parent;
            Form1 f = (Form1)p.Parent.Parent.Parent;
            ClassTab c = (ClassTab)p.Parent;
            Control con = p.TabPages[p.SelectedTab.Name].Controls["txt_message"];
            Control chat = p.TabPages[p.SelectedTab.Name].Controls["text_chat"];

            //MessageBox.Show(c.Name);

            if (!String.IsNullOrEmpty(con.Text))
            {
                switch (m_ChatType)
                {
                    case "WHISPER":
                        f.SendMessage(Form1.MessageType.WHISPER_MESSAGE, con.Text, c.CharID, m_whisper_partner);
                        lock (chat)
                        {
                            chat.Text += "[" + c.Name + "]: " + con.Text + "\r\n";
                        }
                        break;
                    case "SAY":
                        f.SendMessage(Form1.MessageType.SAY_MESSAGE, con.Text, c.CharID, m_whisper_partner);
                        lock (chat)
                        {
                            chat.Text += "[" + c.Name + "]: " + con.Text + "\r\n";
                        }
                        break;
                    case "YELL":
                        f.SendMessage(Form1.MessageType.YELL_MESSAGE, con.Text, c.CharID, m_whisper_partner);
                        lock (chat)
                        {
                            chat.Text += "[" + c.Name + "]: " + con.Text + "\r\n";
                        }
                        break;
                    case "GUILD":
                        f.SendMessage(Form1.MessageType.GUILD_MESSAGE, con.Text, c.CharID, m_whisper_partner);
                        lock (chat)
                        {
                            chat.Text += "[" + c.Name + "]: " + con.Text + "\r\n";
                        }
                        break;
                    case "BG":
                        f.SendMessage(Form1.MessageType.BATTLEGROUND_MESSAGE, con.Text, c.CharID, m_whisper_partner);
                        lock (chat)
                        {
                            chat.Text += "[" + c.Name + "]: " + con.Text + "\r\n";
                        }
                        break;
                    case "PARTY":
                        f.SendMessage(Form1.MessageType.PARTY_MESSAGE, con.Text, c.CharID, m_whisper_partner);
                        lock (chat)
                        {
                            chat.Text += "[" + c.Name + "]: " + con.Text + "\r\n";
                        }
                        break;
                }

                con.Text = "";


            }
            else
            {
                MessageBox.Show("Please type in a message", "Info");
            }
        }

        void send_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                SendMessageToWow();
            }
        }

        void send_Click(object sender, EventArgs e)
        {


            SendMessageToWow();

        }

    

    }
}
